<?php

namespace App\Common\Models;

use App\Models\ApiSoftDeletes;
use App\Models\BaseModel;

class SysEmailTaskModel extends BaseModel
{
    use ApiSoftDeletes;
    protected $table = 'sys_email_task';

    /** @var int 发送完成 */
    const SEND_STATUS_COMPLETED = 1;
    /** @var int 发送失败 */
    const SEND_STATUS_FAILED = 2;

    const TPL_CONTENT = 'mail.content';
    /**
     * 获取发送列表
     * @param $limit
     * @return array
     */
    public function getSendEmailList($limit)
    {
        $where = [
            'status' => 0,
            'send_status' => 0
        ];
        $where[] = ['plan_time', '<=', nowTime()];
        $data = $this->db()->where($where)
            ->limit($limit)
            ->get()->toArray();
        if(!empty($data)) {
            foreach ($data as &$datum) {
                $datum = (array)$datum;
            }
        }
        return $data;
    }
}
